function addEctomyService(ticketId) {
	if (validate4AddEctomyService() == false) {
		return;
	}
	var dt=new Date();
	var hour = dt.getHours()< 10? "0" + dt.getHours(): dt.getHours();
	var min = dt.getMinutes()< 10? "0" + dt.getMinutes(): dt.getMinutes();

	var surgeryDate = $('#inSurgery_yyyy').val() 
	+ '-' 
	+ $('#inSurgery_mm').val()
	+ '-'
	+ $('#inSurgery_dd').val()
	+ ' '
	+ hour + ':' + min + ':00' ;
	
	
	var doctorId = $("select#inputEctomyDoctor :selected").val();
	var surgeryId = $("#surgeryId").val();
	

	$.ajax({
		type:		"GET",
		url:	"../InPatientEctomy/AddEctomyAjax?set_ajax_view",
		data: 	"ticketId=" + ticketId 
		+ "&surgeryDate=" + surgeryDate 
		+ "&doctorId=" + doctorId
		+ "&ectomyServiceId=" + surgeryId,		
		dataType:   "json",
		beforeSend: function() {
			showAjaxLoader('reloadInputEctomy', 'innerLoadingInputEctomy', false);
		},
		success: 	function(data) {			
		if (data.error.code == 'OK') {
			var serviceType = $('#catergoryId').val();
			displayForm4InputService(ticketId, serviceType);

		} else {
			displayError(data.error.mess);				
		}
		showAjaxLoader('reloadInputEctomy', 'innerLoadingInputEctomy', true);

	}
	});	

}

function validate4AddEctomyService() {
	if (!checkMonth($('#inSurgery_mm'),true,'','#statusMessage')) {
		$('#statusMessage' + ticketId).show();
		return false;
	} 

	if (!checkDay($('#inSurgery_dd'),true,'','#statusMessage')) {
		$('#statusMessage' + ticketId).show();	
		return false;
	}	

	var res 	= 	checkDate($('#inSurgery_yyyy'),
			$('#inSurgery_mm'),
			$('#inSurgery_dd'), true, '', '#statusMessage', false);	

	if(!res){	
		$('#statusMessage').show();
		return false;
	}
	if (validateSelectBox("inputServiceSurgeryList", _("Service not selected yet"), "statusMessage") == false) {
		return false;
	}
	if (validateSelectBox("inputEctomyDoctor", _("Doctor not selected yet"), "statusMessage") == false) {
		return false;
	}
	return true;
}

function submitDeleteInPatientEctomy(ticketId, inpatientEctomyId) {
	$.ajax({
		type:		"GET",
		url:	"../InPatientEctomy/DeleteInPatientEctomyAjax?set_ajax_view",
		data: 	"ticketId=" + ticketId	+ "&surgeryId=" + inpatientEctomyId,		
		dataType:   "json",
		success: 	function(data) {			
		if (data.error.code == 0) {
			var serviceType = $('#catergoryId').val();
			displayForm4InputService(ticketId, serviceType);

		} else {
			displayError(data.error.mess);				
		}

	}
	});	
}

function deleteInPatientEctomy(ticketId, inpatientEctomyId) {
	promptConfirm(_("Delete"),_("Are you sure to delete this ectomy?"), function() {
		submitDeleteInPatientEctomy(ticketId, inpatientEctomyId); 
			return true;
		},'YesNo','warn',_('No'));
}